<template>
    <div>
        {{loginForm}}
    <el-form ref="form" :model="loginForm" label-width="180px">
    <el-form-item label="用户名">
        <el-input v-model="loginForm.loginName"></el-input>
    </el-form-item>
    <el-form-item label="密码">
        <el-input type="password" v-model="loginForm.password"></el-input>
    </el-form-item>
    
    <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
        <el-button>取消</el-button>
    </el-form-item>
    </el-form>
       
    </div>
</template>

<script>
export default {
    data(){
        return{
            activeName: 'first',
            loginForm:{
                loginName:'',
                password:''
            }
        }
    },
    methods:{
        login(){
            axios.post("http://localhost:8086/api/user/login",this.loginForm).then(res => {
                if (res.data.flag){
                    this.$message.success(res.data.msg);

                    sessionStorage.setItem("token",res.data.data.token)
                    sessionStorage.setItem("userid",res.data.data.userid)
                    sessionStorage.setItem("username",res.data.data.username)
                    sessionStorage.setItem("type",res.data.data.type)
                    this.$router.push("list");
                }else{
                    this.$message.error(res.data.msg)
                }
            })
            
        }
       
    },
    //8个生命周期函数
    mounted(){
        console.log("mounted")
    }
}
</script>

<style>

</style>


